using huqiang.Core.HGUI;
using System;
using UnityEngine;
using System.IO;
using huqiang.Data;
using huqiang.UIModel;
using UnityEngine.Networking;
using System.Text;

public class HotData
{
    public bool hot;
    public byte[] dll;
    public byte[] ui;
    public byte[] pdb;
}
public class LoadingPage:UIPage
{
    static AssetBundle scene;
    //反射UI界面上的物体
    class View
    {
        public HImage FillImage;
        public HText Tips;
    }
    View view;
    bool loadingScene;
    string nextPage;
    HotData hot;
    bool VersionValidat;
    public override void Initial(UIElement parent, object dat = null)
    {
        base.Initial(parent, dat);
        view = LoadUI<View>("baseUI", "LoadingPage");//"baseUI"创建的bytes文件名,"page"为创建的页面名
        view.FillImage.SizeChanged = (o) => { SetProgress(fill); };
    }
    public override void Cmd(string cmd, object dat)
    {
        switch (cmd)
        {
            case "checkVersion":
                nextPage = "HotFix";
                hot = new HotData();
                hot.hot = (bool)dat;
                LocalSetting.IsEditor = !hot.hot;
                AssetsManager.Start();
                break;
        }
    }

    float fill;
    bool loading;
    void SetProgress(float r)
    {
        fill = r;
        view.FillImage.FillAmount = r;
        float a = view.FillImage.SizeDelta.x;
        float t = 75 + (140 - 75) * (1 - r);
        var col = Color.HSVToRGB(t / 255, 1, 1);
        view.FillImage.MainColor = col;
    }
    public override void Update(float time)
    {
        AssetsManager.Update();
        var step = AssetsAction.GetCurrentStep();
        if(step==null)
        {
            LoadPage<HotFixPage>(hot);//将数据传入热更新管理页面
        }
        else
        {
            view.Tips.Text = step.Tips;
            SetProgress(step.Progress);
        }
    }
}